package com.android.hedgehog.puzzles;

import java.util.Random;

import android.util.Log;

public class Puck {
	public float x, y;
	float dirX, dirY;

	public Puck(float x, float y, float dirX, float dirY) {
		this.x = x;
		this.y = y;
		this.dirX = dirX;
		this.dirY = dirY;
	}
	public void update(float deltaTime) {
		x = x + dirX * deltaTime;
		y = y + dirY * deltaTime;

		if (x < 0) {
			dirX = -dirX;
			x = 0;
		}

		if (x > 290) {
			dirX = -dirX;
			x = 290;
		}

		if (y < 30) {
			dirY = -dirY;
			y = 30;
		}

		if (y > 480) {
			dirY = -dirY;
			y = 480;
		}

	}

	public boolean checkCollision(Block block) {
		if ((y + 30) > block.y1 && y + 20 < block.y1) {// BLOCKED (2-diff)
			if (x > block.x1 && x < block.x2) {// R->L
				dirY = -dirY;
				// x = block.x1 - 30;
				Log.d("BLOCK1", "PUCK: x: " + x + " y: " + y + " x2: "
						+ (x + 30) + " y2: " + (y + 30));
				return true;
			}
			if ((x + 30) > block.x1 && (x + 30) < block.x2) {
				dirY = -dirY;
				// x = block.x2;
				Log.d("BLOCK2", "PUCK: x: " + x + " y: " + y + " x2: "
						+ (x + 30) + " y2: " + (y + 30));
				return true;
			}

		}// BLOCKED

		if (((y + 30) > block.y1 && y < block.y1)
				|| ((y + 30) > block.y2 && y < block.y2)) {
			if (x > block.x1 && x < block.x2) {// BOUNCE RIGHT
				dirX = -dirX;
			}
			if ((x + 30) > block.x1 && (x + 30) < block.x2) {// BOUNCE LEFT
				dirX = -dirX;
			}
		}

		return false;
	}

	public boolean checkGoal() {
		if (y > 450) {
			return true;
		}
		return false;
	}

}